home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CGAMEJOY.ARJ / TESTLOW.C < prev    next >
C/C++ Source or Header  |  1992-01-08  |  7KB  |  194 lines

  1. /* testlow.c    
  2.                 Test for low level game-adapter procedures in joystklo.c.
  3.                 Quits if no peripheral (joystick) is detected at port 201h.
  4.  
  5.                 written for Borland C++ 2.0 ;
  6.  
  7.                 to complile :
  8.                             bcc testlow.c joystklo.c
  9.                         or
  10.                             bcc -ms testlow.c joystk_s.lib
  11.  
  12.                 by Ed Torgerson : CIS 70313,456,  GEnie E.TORGERSON1.
  13.                 any constructive correspondence is welcome.
  14.  
  15. -----------------------------------------------------------------------------*/
  16.  
  17. #include <stdio.h>
  18. #include <conio.h>
  19. #include <dos.h>
  20. #include "joystick.h"
  21.  
  22. void  main(void)
  23. {
  24.     int     oldA1, newA1, oldA2, newA2 ;
  25.     int     oldB1, newB1, oldB2, newB2 ;
  26.     int     i ;
  27.     char    down[5] = "down" ;
  28.     char    up[5]   = "up  " ;
  29.  
  30.     oldA1 = newA1 = oldA2 = newA2 = 0 ;
  31.     oldB1 = newB1 = oldB2 = newB2 = 0 ;
  32.     i = 0 ;
  33.  
  34.     clrscr () ;
  35.     i = JstDetect () ;
  36.  
  37.     if ( i == 0 )
  38.     {
  39.         printf ("Joystick not detected.") ;
  40.         return ;
  41.     }
  42.     printf ("Joystick detected by JstDetect():\n") ;
  43.     if ( (i & JAX_AXIS) != 0 )
  44.             printf("\tJoystick A x-axis is valid.\n" );
  45.     if ( (i & JAY_AXIS) != 0 )
  46.             printf("\tJoystick A y-axis is valid.\n" );
  47.     if ( (i & JBX_AXIS) != 0 )
  48.             printf("\tJoystick B x-axis is valid.\n" );
  49.     if ( (i & JBY_AXIS) != 0 )
  50.             printf("\tJoystick B y-axis is valid.\n" );
  51.     printf ( "\n" ) ;
  52.     printf ( "JstGetActiveAxes() - %02xh\n", JstGetActiveAxes() ) ;
  53.     printf ( "JstGetValidAxes()  - %02xh\n", JstGetValidAxes() ) ;
  54.     i = JstGetValidAxes() ;
  55.     i = i ^ 0xf ;
  56.     JstSetActiveAxes ( (unsigned) i ) ;
  57.     printf ( "\nAttempting to set invalid active axis\nJstSetActiveAxes " ) ;
  58.     printf ( "(%02xh) == %d", i, JstSetActiveAxes ( (unsigned) i ) ) ;
  59.     printf ( "\t\tActive_Axes - %02xh\n", JstGetActiveAxes() ) ;
  60.     i = JstGetValidAxes() ;
  61.     i = i & 0x5 ;
  62.     printf ( "\nAttempting to set valid active axis\nJstSetActiveAxes " ) ;
  63.     printf ( "(%02xh) == %d", i, JstSetActiveAxes ( (unsigned) i ) ) ;
  64.     printf ( "\t\tActive_Axes - %02xh\n", JstGetActiveAxes() ) ;
  65.     i = JstGetValidAxes() ;
  66.     printf ( "\nAttempting to reset original active axis\nJstSetActiveAxes " ) ;
  67.     printf ( "(%02xh) == %d", i, JstSetActiveAxes ( (unsigned) i ) ) ;
  68.     printf ( "\t\tActive_Axes - %02xh\n", JstGetActiveAxes() ) ;
  69.  
  70.     printf ("\n\n\nany key to continue...\n") ;
  71.     getch() ;
  72.  
  73.     /*----- Current Button Status Test --------------------------------------*/
  74.  
  75.     clrscr () ;
  76.     printf ("JstGetButton()       gets current button status\n") ;
  77.     printf ("any key to continue...\n") ;
  78.     gotoxy (10, 10) ;
  79.     printf ( "Joystick A Button 1 is " ) ;
  80.     gotoxy (10, 11) ;
  81.     printf ( "Joystick A Button 2 is " ) ;
  82.     gotoxy (10, 12) ;
  83.     printf ( "Joystick B Button 1 is " ) ;
  84.     gotoxy (10, 13) ;
  85.     printf ( "Joystick B Button 2 is " ) ;
  86.  
  87.     while( !kbhit() )
  88.     {
  89.         i = JstGetButton () ;
  90.         gotoxy (33, 10) ;
  91.            if ( (i & JA1_BUTTON_DOWN) )
  92.                printf ( "%s", down ) ;
  93.            else
  94.                printf ( "%s", up ) ;
  95.         gotoxy (33, 11) ;
  96.            if ( (i & JA2_BUTTON_DOWN) )
  97.                printf ( "%s", down ) ;
  98.            else
  99.                printf ( "%s", up ) ;
  100.         gotoxy (33, 12) ;
  101.            if ( (i & JB1_BUTTON_DOWN) )
  102.                printf ( "%s", down ) ;
  103.            else
  104.                printf ( "%s", up ) ;
  105.         gotoxy (33, 13) ;
  106.            if ( (i & JB2_BUTTON_DOWN) )
  107.                printf ( "%s", down ) ;
  108.            else
  109.                printf ( "%s", up ) ;
  110.         delay ( 50 ) ;
  111.     }
  112.     getch() ;
  113.  
  114.     clrscr () ;
  115.     printf ( "JstGetChangedButton() returns button values ") ;
  116.     printf ( "only if they've changed.\n") ;
  117.     printf ( "JstGetPosition() returns the current position") ;
  118.     printf ( " of valid joystick axes.\n") ;
  119.     printf ( "For this demonstration, only changes greater than") ;
  120.     printf ( " 2 units are reported.\n\n\n") ;
  121.  
  122.     delay (100) ;
  123.  
  124. do_test_loop:
  125.  
  126.     while( !kbhit() )
  127.     {
  128.     /*----- Changed Button Status Test -----------------------------------*/
  129.         i = JstGetChangedButton () ;
  130.  
  131.         if ( (i & JA1_BUTTON_DOWN) != 0 )
  132.             printf("Joystick A Button 1 down\n" );
  133.         if ( (i & JA1_BUTTON_UP  ) != 0 )
  134.             printf("Joystick A Button 1     up\n" );
  135.         if ( (i & JA2_BUTTON_DOWN) != 0 )
  136.             printf("Joystick A Button 2 down\n" );
  137.         if ( (i & JA2_BUTTON_UP  ) != 0 )
  138.             printf("Joystick A Button 2     up\n" );
  139.         if ( (i & JB1_BUTTON_DOWN) != 0 )
  140.             printf("Joystick B Button 1 down\n" );
  141.         if ( (i & JB1_BUTTON_UP  ) != 0 )
  142.             printf("Joystick B Button 1     up\n" );
  143.         if ( (i & JB2_BUTTON_DOWN) != 0 )
  144.             printf("Joystick B Button 2 down\n" );
  145.         if ( (i & JB2_BUTTON_UP  ) != 0 )
  146.             printf("Joystick B Button 2     up\n" );
  147.         delay ( 6 ) ;
  148.  
  149.     /*----- Joystick A Position Test --------------------------------------*/
  150.         newA1 = JstGetPosition ( JAX_AXIS ) ;
  151.         newA2 = JstGetPosition ( JAY_AXIS ) ;
  152.  
  153.         if ( (newA1 != 0) || (newA2 != 0) )
  154.         {
  155.             if ( (newA1 < (oldA1 - 2) ) || (newA1 > (oldA1 + 2) ) ||
  156.                  (newA2 < (oldA2 - 2) ) || (newA2 > (oldA2 + 2) ) )
  157.             {
  158.                 printf("Joystick A      \t   %3dx    %3dy real\n", newA1, newA2 );
  159.                 oldA1 = newA1 ;
  160.                 oldA2 = newA2 ;
  161.             }
  162.         }
  163.         delay ( 6 ) ;
  164.  
  165.     /*----- Joystick B Position Test --------------------------------------*/
  166.         newB1 = JstGetPosition ( JBX_AXIS ) ;
  167.         newB2 = JstGetPosition ( JBY_AXIS ) ;
  168.  
  169.         if ( (newB1 != 0) || (newB2 != 0) )
  170.         {
  171.             if ( (newB1 < (oldB1 - 2) ) || (newB1 > (oldB1 + 2) ) ||
  172.                  (newB2 < (oldB2 - 2) ) || (newB2 > (oldB2 + 2) ) )
  173.             {
  174.                 printf("Joystick B      \t   %3dx    %3dy real\n", newB1, newB2 );
  175.                 oldB1 = newB1 ;
  176.                 oldB2 = newB2 ;
  177.             }
  178.         }
  179.         delay ( 6 ) ;
  180.     }
  181.     i = getch () ;
  182.     if ( (i == 59) )
  183.     {
  184.         clrscr () ;
  185.         printf("\n\n\t\t\tPress escape to quit.\n\n") ;
  186.         goto do_test_loop ;
  187.     }
  188.     if ( (i != 27) )
  189.         goto do_test_loop ;
  190.  
  191. }
  192.  
  193. /*-- end testlow.c ----*/
  194.